﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LenderClearingHouse
{
  public partial class MyInvestments : GridPage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      listFilter.SearchButton.Click += new ImageClickEventHandler(SearchButton_Click);
      RadAjaxManager.AjaxSettings.AddAjaxSetting(Grid, Grid);
    }

    void SearchButton_Click(object sender, ImageClickEventArgs e)
    {
      Grid.Rebind();
      listFilter.ClearFilter();
    }

    protected override SourcePage GetSourcePage()
    {
      return CurrentUser.SubRole == UserSubRole.LVReo ? SourcePage.LvreoList : SourcePage.SdreoList;
    }

    protected override SqlDataSource GetSqlDataSource()
    {
      return sqlDataSource;
    }

    protected override ListFilterControl GetListFilterControl()
    {
      return listFilter;
    }

    protected override Control GetGridContainer()
    {
      return phGrid;
    }

    protected override string GetDataSourceID()
    {
      return sqlDataSource.ID;
    }

    protected override void SetupSqlDataSource(SqlDataSource dataSource)
    {
      base.SetupSqlDataSource(dataSource);

      dataSource.SelectParameters.Add(new Parameter()
      {
        ConvertEmptyStringToNull = false,
        Name = "currentUserId",
        Type = TypeCode.Int32
      });

      dataSource.Selecting += new SqlDataSourceSelectingEventHandler(dataSource_Selecting);
    }

    void dataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
      e.Command.Parameters["@currentUserId"].Value = CurrentUser.UserId;
    }
  }
}